package com.ithaima.a_cookie.com.itheima.utils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/killServlet")
public class KillServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.创建一个同名的Cookie
        Cookie c = new Cookie("lastTimeCookie","aa");
        //2.设置持久化的时间为零
        c.setMaxAge(0);
        //3/设置相同有效路径
        c.setPath(request.getContextPath());
        //4.返回到浏览器覆盖原来的Cookie
        response.addCookie(c);

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

}
